#!/bin/bash
###########################################
## 功能：自动的将应用程序产生的日志同步到 flume 配置指定的目录下(本地)
## 用法：直接部署 crontab 或者本地 debug：bash -x cpM_trackToFlume.sh [N]
## crontab 部署方式：logs 目录需要自己手动创建！
## create: 2015-08-26
###########################################

. /home/hongxi/baseUtil.sh

dt=`date +"%Y-%m-%d-%H" -d "-1 hours"`

filename=nobita.${dt}.log

srcfile1=/data2/logs/dsp/prod1/nobita/${filename}
srcfile2=/data2/logs/dsp/prod2/nobita/${filename}

srctmp=/data2/logs/flume/tmp

dstfile=/data2/logs/flume/spooling/arr/nobita

wareinginfo=/home/hongxi/logs/cpnobitalog_flume.log

echo "     " >> $wareinginfo
echo "---------------------------------" >> $wareinginfo
echo $(date +"%y-%m-%d %H:%M:%S") >> $wareinginfo
echo "---------------------------------" >> $wareinginfo

if [ -f "$srcfile1" ]; then 
	echo $srcfile1 
	#echo $srctmp/${filename}
	echo $dstfile
	cp $srcfile1 $srctmp/${filename}."1" >>$wareinginfo

fi 

if [ -f "$srcfile2" ]; then 
	echo $srcfile2 
	#echo $srctmp/${filename}
	echo $dstfile
	cp $srcfile2 $srctmp/${filename}."2" >>$wareinginfo
fi 

cat $srctmp/${filename}.* >> $srctmp/${filename} 
#rm $srctmp/${filename}.*
mv $srctmp/${filename} $dstfile >>$wareinginfo

